"""
Author : sunshicheng
DateTime : 2021/6/4.3:16 下午
FileName : locust_order.py
Desc: 接口执行顺序
"""
import sys
from locust import TaskSet, SequentialTaskSet, HttpUser, task, constant

sys.path.append('..')
from config.base_info import Static_info as si
from config.user_token import Token

token = Token('18226287291')
headers = token.test_token()


class MyTask(SequentialTaskSet):
    @task(1)
    def get_test(self):
        data = {"account": "sunshicheng"}
        # 发送get请求，加上name，就会展示传入的name名称
        with self.client.get(si.inter['saas']['saas_permission'], params=data, headers=headers, name='获取用户权限',
                             catch_response=True) as result:
            # 耗时多少
            # print('耗时', result.elapsed.total_seconds())
            print(1)
            # 结果的值在不在里
            if 'SUCCESS。' in result.text:
                result.success()
            else:
                # 错误信息可以自己定义
                result.failure(str(result.text))

    @task(10)
    def test_get_1(self):
        data = {"account": "1009"}
        # 发送get请求，加上name，就会展示传入的name名称
        with self.client.get(si.inter['saas']['saas_permission'], params=data, headers=headers, name='获取用户权限_1',
                             catch_response=True) as result:
            # 耗时多少
            # print('耗时', result.elapsed.total_seconds())
            print(2)
            # 结果的值在不在里
            if 'SUCCESS。' in result.text:
                result.success()
            else:
                # 错误信息可以自己定义
                result.failure(str(result.text))


class MyUsers(HttpUser):
    tasks = [MyTask]
    wait_time = constant(0.1)
